float
¶number = 3.1415
type(number)
float
float('3.1415') * 2
6.283
round
¶round(3.14159, 2)
3.14
round(3.14159, 4)
3.1416
apples = 7
people = 3
per_person = apples / people
print(f'Each person gets { per_person } apples')
Each person gets 2.3333333333333335 apples
apples = 7
people = 3
per_person = round(apples / people, 1)
print(f'Each person gets { per_person } apples')
Each person gets 2.3 apples
recipe.py
¶Write a program that allows the user to input a list of ingredients.
For each ingredient, they should provide the item, the quantity, and the units (e.g. cups, tsps, etc.)
Then query the user for the scaling factor (how much do they want to scale the recipe).
Then print out the recipe scaled by that factor. Round to 1 decimal place.
What ingredients are in your recipe? Ingredient: flour Quantity: 2 Unit: cups Ingredient: salt Quantity: 1 Unit: tbs Ingredient: baking soda Quantity: 1 Unit: tsps Ingredient: water Quantity: 1 Unit: cups Ingredient: Scaling factor: 2.5 New Recipe: 5.0 (cups) flour 2.5 (tbs) salt 2.5 (tsps) baking soda 2.5 (cups) water
fishing.py
¶Write a program that allows the user to input information on a series of catches.
For each catch, the user should provide the place, type, and size (in inches) of the fish.
Then allow the user to specify which types of fish to report on. For each type specified, print a report indicating:
Place: Utah Lake Type of fish: Trout Size (inches): 6 Place: Lake Powell Type of fish: Bass Size (inches): 12 Place: Flaming Gorge Type of fish: Bass Size (inches): 18 Place: Strawberry Type of fish: Trout Size (inches): 13 Place: Bear Lake Type of fish: Trout Size (inches): 15 Place: What types of fish do you want to report on? Type: Bass Type: Trout Type: Total # of Bass: 2 Average size for Bass: 15.0 Best Bass catch: 18.0 inches at Flaming Gorge Total # of Trout: 3 Average size for Trout: 11.3 Best Trout catch: 15.0 inches at Bear Lake